package com.itanty.spring.test;

import com.itanty.spring.dao.UserDao;
import com.itanty.spring.entity.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * @date 2025/9/24
 */
public class test02 {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao = (UserDao) ac.getBean("userDao");
//        User user = new User("lucy","123456","12345678901","江苏-南京");
//        userDao.insertUser(user);

        User user = new User("tom", "123456", "13612369866", "江苏-南京");
        Integer id = userDao.insertReturnPrimaryKey(user);
        System.out.println("保存成功,返回的主键值为:" + id);

        List<User> users = userDao.selectAll();
        users.forEach(System.out::println);

//        userDao.deleteById(4);
//        User user = new User(3,"jack","123456","10987654321","广东东莞");
//        userDao.updateUser(user);
//        System.out.println("**************************************************");
//        User user = userDao.selectById(3);
//        System.out.println(user);

    }
}
